export default function (url, { body, headers, success, fail, ...callbacks }) {
  const xhr = new XMLHttpRequest()
  Object.assign(xhr.upload, callbacks)
  xhr.onreadystatechange = function () {
    if (xhr.readyState === 4) {
      if (xhr.status === 200) {
        success && success(xhr.response)
      } else {
        fail && fail(xhr.response)
      }
    }
  }
  xhr.open('POST', url, true)
  xhr.send(body)
}
